<html lang ="en">
	<head> <title>CSE 471 Audio Synthesizer</title> </head>
	<body>
        <hgroup id="page-head">
            <h1>Additive Synthesizer: Eric Slenk</h1>
        </hgroup>

        <div id="files">
            <h2>Files</h2>
            <ul> 
                <li><a href="AdditiveSynth.score">Sample score</a></li>
                <li><a href="AdditiveSynth.wav">Sample output</a></li>
            </ul>
        </div>

        <div id="grading">
            <h2>Grading Criteria</h2>
            <dl id="grading-list">
                <dt>Playback on Demand</dt>
                    <dd>
                        <p>The additive synthesizer was implemented as a caching synthesizer. The synth's factory class maintains a wavetable implemented as a map from wstring note names, such as "Bb4", to wave sample vectors. Each time a note is set from the sequencer, the factory performs a lookup to see whether the note exists in the table.</p>
                        <p>If the note does not exist in the map, the factory utilizes a member CSineWave to generate a sample vector for its pitch. This vector contains doubles representing exactly one waveform. Each harmonic is also generated and summed into the sample vector. After summation of all required harmonics, the sample wave is inserted in the map witch the note name as its key, and the program moves on to playback.<p>
                        <p>Once the note is cached, the additive synth class generates samples for as long as the instrument's ADSR class dictates. It does this by getting a pointer into the given note's sample vector and iterating through the vector, circling back to the beginning as necessary.</p>
                    </dd>
                <dt>Definition of Harmonics</dt>
                    <dd>
                        <p>Each sample wave vector is generated as a fundamental sine wave (wave[t] = SineWave(t, freq)). For each harmonic, for each sample in the fundamental, a sample is calculated and summed into the vector. Each harmonic sample is the sample of a sine wave with the harmonic's frequency at the given point in time multiplied by the harmonic's amplitude (wave[t] += amplitude[harmonic] * SineWave(t, freq*harmonic)).</p>
                        <p>Harmonics are represented in the score file as an element &lt;harmonics&gt; containing a space-separated list of doubles, representing the amplitude of each harmonic. For example, &lt;harmonic&gt;1.0 0.0 0.0 0.0 0.2&lt;/harmonic&gt; defines the fundamental at amplitude 1 and the 5th harmonic at amplitude 0.2. Any undefined harmonics are assumed to be 0. Any number of harmonics may be defined, though the factory defaults to 8.</p>
                        <p>Each time a new set of harmonics is defined, the wave table in the synth's factory must be flushed, as a change in amplitudes changes the sound of the wave at each pitch.</p>
                    </dd>
                <dt>Envelope</dt>
                    <dd>
                        <p>The additive instrument pipes all samples into the ADSR envelope for audio playback.</p>
                    </dd>
                <dt>Polyphony</dt>
                    <dd><p>Multiple notes from a single wavetable may be played at the same time. However, due to the design of the factory and table, changing harmonics multiple times while sustaining notes should cause a segmentation fault, as the tables the synths point to would be dropped.</p></dd>
                <dt>Crossfading and Glissando</dt>
                    <dd>
                        <p>These features were not implemented.</p>
                        <p>The factory maintains two wavetables to facilitate these features. Crossfading would have taken samples from the new and current tables for each sample and summed them, weighting each sample according to time. Glissando would have generated all notes between the targets and interpolated between the samples from one note to the next.</p>
                    </dd>
            </dl>
        </div>
	</body>
</html>
